package com.atguigu.gulimall.search.web;

import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @ ClassName IndexController
 * @ Description TODO
 * @ Author admin
 * @ Date 2021/3/8 15:13
 * @ Version 1.0
 */
@Controller
public class IndexController {

    @Autowired
    MallSearchService mallSearchService;

    @GetMapping({"/index.html","list.html"})
    public String toSearchIndex(SearchParam searchParam, Model model, HttpServletRequest request)
    {
        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResult searchResponse =  mallSearchService.search(searchParam);
        model.addAttribute("result",searchResponse);
        return "index";
    }

}
